const WXAPI = require('../../wxapi/main')

Page({
    data: {
        zdy: ''
    },

    onLoad: function (e) {
        const that = this;

        WXAPI.shopSubdetail(1020624).then(function (res) {

            let temp = res.data.content;
            // 假设 html 内容变量为 htmlContent
            let htmlContent = temp.replace(
                /<img\b(?![^>]*style=)[^>]*>/gi,
                function (imgTag) {
                    // 如果已有style则追加，否则直接加
                    if (/style=/.test(imgTag)) {
                        return imgTag.replace(/style=["'][^"']*["']/, function (styleStr) {
                            return styleStr.replace(/["']$/, ';width:100%;height:auto; display: block;margin: 0;padding: 0;float:left;margin-top:-1px;"');
                        });
                    } else {
                        return imgTag.replace('<img', '<img style="width:100%;height:auto; display: block;margin: 0;padding: 0;float:left;margin-top:-1px;"');
                    }
                }
            );

            htmlContent = htmlContent.replace(/\s+/g, ' ').trim(); // 移除多余的空白字符

            console.log("shopSubdetail", htmlContent);


            that.setData({
                zdy: htmlContent
            });
        }).catch(function (e) {
            wx.showToast({
                title: res.msg,
                icon: 'none'
            })
        })

    },

     // 分享
     onShareAppMessage: function () {
        return {
            title: "GOOD STUDIO儿童摄影",
            path: "/pages/index/my"
        };
    },

    onShareTimeline: function () {
        return {
            title: "GOOD STUDIO儿童摄影",
        }
    },


    // 侧栏
    tel: function () {
        wx.makePhoneCall({
            phoneNumber: wx.getStorageSync('shopSubdetail').info.linkPhone,
        })
    },
    sc: function () {
        wx.navigateTo({
            url: '/pages/index/sc'
        })
    },
    onPageScroll: function (e) {
        // 页面滚动时触发
        // console.log('页面滚动，当前滚动位置：', e.scrollTop);
        if (e.scrollTop > 100) {
            this.setData({
                showUp: true
            })
        } else {
            this.setData({
                showUp: false
            })
        }
    },
    up: function () {
        //   点击返回顶部
        wx.pageScrollTo({
            scrollTop: 0,
            duration: 300
        })
    },


    gomy: function () {
        wx.navigateTo({
            url: '/pages/index/my'
        })
    }
});